<?php
declare(strict_types=1);

namespace app\admin\service;

use app\admin\model\RequirementsForm as RequirementsFormModel;

class RequirementsFormService
{
    /**
     * 需求总数
     * @param array $where
     * @return int
     */
    public static function countRequirementsForm($where = [])
    {
        return RequirementsFormModel::countRequirementsForm($where);
    }

    /**
     * 当日新增需求
     * @return int
     */
    public static function todayRequirementsForm()
    {
        return RequirementsFormModel::todayRequirementsForm();
    }

    /**
     * 需求分类
     * @return array
     */
    public static function requirementsFormCate()
    {
        $requirementsFormCate = RequirementsFormModel::requirementsFormCate();
        $colorArr = [];
        $datas = [];
        foreach ($requirementsFormCate as $k => $v) {
            $colorArr[] = $v['color'];
            $datas[] = json_encode([
                'name' => $v['name'],
                'value' => $v['nums'],
            ], JSON_UNESCAPED_UNICODE);
        }
        $line_data['colors'] = join(',', $colorArr);
        $line_data['datas'] = join(';', $datas);
        return ['requirementsFormCate' => $requirementsFormCate, 'line_data' => $line_data];
    }
}